import { asyncTasks } from '../utils/roc'
import db from '../app/database'
import Api from '../utils/Api'

class UserService extends Api {
  /**
   * 获取用户信息
   */
  async getUserById(userId: number) {
    const sql = `SELECT id,username,nickname,avatar,add_time,update_time FROM roc_user WHERE id = ?;`
    const [err, results] = await asyncTasks(db.query(sql, [userId]))
    if (err) return console.log('sql错误:', err.sqlMessage)
    const users = results[0]
    if (users.length) {
      return this.success(users[0])
    } else {
      return this.error('无此用户')
    }
  }
}

export default new UserService()
